package com.wangc.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class TestFilter extends HttpServlet implements Filter {

	@Override
	public void doFilter(ServletRequest sRequest, ServletResponse sResponse,
			FilterChain fChain) throws IOException, ServletException {
		HttpServletResponse response = (HttpServletResponse) sResponse;
		HttpServletRequest request = (HttpServletRequest) sRequest;
		String name = sRequest.getParameter("name");
		HttpSession session = request.getSession();
		System.out.println("====>>name:"+name);
		if(null == name){
			response.sendRedirect("other.jsp");
		}
		
		if("wang".equals(name)){
			System.out.println("====>>if:");
			request.setAttribute("na", "wangwang");
//			response.sendRedirect("wang.jsp");
//			return ;
		}else{
			System.out.println("====>>else:");
			request.setAttribute("na", "otherother");
//			response.sendRedirect("other.jsp");
//			return ;
		}
		fChain.doFilter(sRequest, sResponse);
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}

